<!doctype html>
<html xmlns:th="http://www.w3.org/1999/xhtml">

	<head>
		<th:block th:include="/A0723/include :: header('登录')" />
	</head>

	<body style="overflow: hidden;">
		<div class="mui-content">
			<!-- bg -->
			<div class="login_bg"></div>
			<!-- logo -->
			<div class="logo">
				<img th:src="@{/front/images/logo.png}" alt="">
			</div>
			<!-- input -->
			<div class="login_form">
				<div class="mui-input-row">
					<label><i class="iconfont icon-shouji3"></i></label>
					<input type="text" id="phone" placeholder="请输入手机号">
				</div>
				<div class="mui-input-row">
					<label><i class="iconfont icon-mima4"></i></label>
					<input type="password" id="password" placeholder="请输入密码">
				</div>
				<!-- 注册 忘记密码 -->
				<div class="wj_zc flex3">
					<a href="toRegister">立即注册</a>
					<a href="toForget">忘记密码?</a>
				</div>
				<!--  -->
				<button type="button" onclick="login()" class="mui-btn mui-btn-blue mui-btn-block mui_btn">登录</button>
			</div>
		</div>
		<th:block th:include="/A0723/include :: footer" />
		<script type="text/javascript">

			$(function() {

			})
			/**
			 * 获取url参数值
			 * @return {string}
			 */
			function GetQueryString(name) {
				var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
				var r = window.location.search.substr(1).match(reg); //获取url中"?"符后的字符串并正则匹配
				var context = "";
				if (r != null)
					context = r[2];
				reg = null;
				r = null;
				return context == null || context === "" || context === "undefined" ? "" : context;
			}
			let data = {}
			//验证
			function validateLogin() {
				let phone = $("#phone").val();
				if (phone == null || phone === '') {
					mui.toast('请输入手机号', {duration: 'long', type: 'div'})
					return
				}
				let password = $("#password").val();
				if (password == null || password === '') {
					mui.toast('请输入密码', {duration: 'long', type: 'div'})
					return
				}
				data.phone = phone;
				data.password = password;
				return true;
			}
			//登录
			function login() {
				if (validateLogin()) {
					mui.ajax(ctx+'front/release/login',{
						data:data,
						dataType:'json',//服务器返回json格式数据
						type:'post',//HTTP请求类型
						timeout:10000,//超时时间设置为10秒；
						headers:{'Content-Type':'application/json'},
						success:function(res){
							//服务器返回响应，根据响应结果，分析是否登录成功；
							mui.toast(res.msg, {duration: 'long', type: 'div'})
							if(res.code === 0){
								setInterval(function () {
									window.location.href = ctx+'front/toIndex'
								},2000)
							}
						},
						error:function(xhr,type,errorThrown){
							//异常处理；
							console.log(type);
						}
					});
				}
			}
		</script>

	</body>

</html>
